package com.bw.sparksql1.job1

import org.apache.log4j.{Level, Logger}
import org.apache.spark.sql.{DataFrame, SaveMode, SparkSession}

/**
  *
  */
object Job9 {
    def main(args: Array[String]): Unit = {
      Logger.getLogger("org").setLevel(Level.ERROR)
      val spark = SparkSession
        .builder()
        .master("local")
        .appName("Spark SQL basic example")
        .getOrCreate()
      //格式一：parquet
      val df: DataFrame = spark.read.load("users.parquet")
      df.write.save("xxx")//默认保存parquet

      val df1 = spark.read.format("json").load("people.json")
      df1.createOrReplaceTempView("people1")
      spark.sql("select name from people1").write.format("json").save("test.json")
//      spark.sql("select name from people1").write.format("csv").save("test.json")
      spark.sql("select name from people1").write.format("csv").save("test.json")
      spark.sql("select name from people1").write.mode(SaveMode.Append).format("json").save("mode-test.json")
    }
}